package lib.record;

import java.io.IOException;
import java.sql.SQLException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import lib.record.*;
import lib.register.*;
/**
 * Servlet implementation class recorddropServlet
 */
@WebServlet("/recorddropServlet")
public class recorddropServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public recorddropServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		request.setCharacterEncoding("UTF-8");
		String uid=request.getParameter("uid");//输入的图书证号
		String flag=request.getParameter("alter_reco");//获取删除/新增操作的标志
		if(flag.equals("0")) {//0代表删除操作
			recordDao re= new recordDao();
			boolean res= re.dropRecord(uid);
			if(res==true) {
				request.getSession().setAttribute("operate_state", 1);
			}
			else {
				request.getSession().setAttribute("operate_state", 0);
			}
		}
		else {//1代表插入操作
			registerDao re=new registerDao();
			String ustatus=request.getParameter("ustatus");//输入的身份信息
			try {
				boolean res=re.insert("", uid,ustatus, "123456");
				if(res==true) {
					request.getSession().setAttribute("operate_state", 1);
				}
				else {
					request.getSession().setAttribute("operate_state", 0);
				}
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
		request.getRequestDispatcher("manage.jsp").forward(request, response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
